/**
 * Slide Select 
 * @author rubekid 
 */
(function(){
	
	function SlideSelect(options){
		this.init(options);
	}
	
	SlideSelect.prototype = {
		init:function(options){
			this._select = options.target;
			this.initUl();
		},
		initUl:function(){
			var liBuffer = [];
			this._ul = document.createElement("ul");
			this._ul.className = "slide_select";
			this.insertAfter(this._ul, this._select);
			for(var i = 0; i< this._select.options.length; i++){
				var option = this._select.options[i];
				var selected = "";
				if(option.selected){
					selected = "data-selected='true'";
				}
				liBuffer.push('<li '+selected+' title="' +option.title + '" data-value="' + option.value + '" >' + option.text + '</li>');
			}
			this._ul.innerHTML = liBuffer.join('');
			this._select.style.display = "none";
		},
		insertBefore:function(ele, target){
			target.parentNode.insertBefore(ele, target);
		},
		insertAfter:function(ele, target){
			var parent = target.parentNode;
			if(target.nextSibling){
				this.insertBefore(ele, target.nextSibling);
			}
			else{
				parent.appendChild(ele);
			}
		}
	};
	
	window.SlideSelect = SlideSelect;
	
})();
